#!/usr/bin/perl

require './sharelink-lib.pl';

my ($n, %smbcnt, $i, @order, $index, $trcls);

&header($text{'index_title'}, "", "cifs", 0, 1, undef, undef, "<meta http-equiv=refresh content=120>");

$n = &get_smb_list(\%smbcnt);

print "<form action=index.cgi method=post onsubmit='document.forms[0].killcon.disabled=true;'>";


print "<table class=mode1 width=100% border=0 cellspacing=0>";

print "<tr><td valign=top width=90%>";
print "<div style='valign:top;width:100%;height:300;overflow:auto'>";
print "<table class=mode1 width=100% border=0 cellspacing=0>";
print "<tr class=title1>";
print "<th align=left width=20%>$text{'th_dir'}</th><th align=left width=10%>$text{'th_user'}</th><th align=left>$text{'th_machine'}</th><th align=left >$text{'th_ip'}</th><th width=26%  align=left>$text{th_date}</th><th width=20% align=left>$text{'th_openfile'}</th>";
print "</tr>";

if($n < 1)
{	
	print "<tr class=mode1><td colspan=6>$text{'tbsmb_no_items'}</td></tr>";
}

@order = (0..$n-1);
@order = sort { $smbcnt{"$a^dir"} cmp $smbcnt{"$b^dir"} } @order;
for($i = 0; $i < @order; $i++)
{
	$index = $order[$i];
	if($i % 2)
	{
		$trcls = "class=mode2";
	}
	else
	{
		$trcls = "class=mode1";
	}
	print "<tr $trcls>";
	print "<td><input type=radio name=pid value=\"", $smbcnt{"$index^pid"} ,"\"><img src='images/share.gif'>", $smbcnt{"$index^dir"} ,"</td>";
	print "<td>", $smbcnt{"$index^uid"} ,"</td>";
	
	print "<td>", $smbcnt{"$index^machine"}, "</td>";
	print "<td>", $smbcnt{"$index^strip"}, "</td>";
	print "<td>", $smbcnt{"$index^time"}, "</td>";
	my @line;
	@line = split("\n", $smbcnt{"$index^lockfiles"});
	print "<td>";
	print "<table class=mode1 cellspacing=0>";
	my $j;
	for($j = 0; $j < @line; $j++)
	{
		print "<tr>";
		print "<td>$line[$j]</td>";
		print "</tr>";
	}
	print "</table>";
	print "</td>";	
	print "</tr>";
}

print "</table>";
print "</div>";

print "</td><td valign=top>";

print "<table>";
#print "<tr><td><input name=detail type=submit class=button value=\"$text{'bt_detail'}\" onclick=\'return on_submit_detail($n, \"$text{'error_msg_item'}\");\'></td></tr>";
#print "<tr><td><input name=killcon type=submit class=button value=\"$text{'bt_kill_con'}\" onclick=\'return on_submit_killcon($n, \"$text{'error_msg_item'}\");\'></td></tr>";
print "</table>";

print "</td></tr>";
print "</table>";

print "</form>";

print <<EOF;
<script>

function on_submit_detail(tb_length, error_msg)
{
	var i;
	var find=0;

	if(tb_length < 2)
	{
		if(tb_length < 1)
		{
			return false;
		}
		else
		{
			if(document.forms[0].pid.checked)
			{
				find = 1;
			}
		}
	}
	else
	{
		for(i = 0; i < tb_length; i++)
		{
			if(document.forms[0].pid[i].checked)
			{
				find = 1;
			}
		}
	}

        if(find == 0)
        {
                alert(error_msg);
		return false;
        }
	document.forms[0].action = 'cifsdetail.cgi';
}

function on_submit_killcon(tb_length, error_msg)
{
	
	var i;
	var find=0;

	if(tb_length < 2)
	{
		if(tb_length < 1)
		{
			return false;
		}
		else
		{
			if(document.forms[0].pid.checked)
			{
				find = 1;
			}
		}
	}
	else
	{
		for(i = 0; i < tb_length; i++)
		{
			if(document.forms[0].pid[i].checked)
			{
				find = 1;
			}
		}
	}

        if(find == 0)
        {
                alert(error_msg);
		return false;
        }
	document.forms[0].action = 'cifskill.cgi';

}

</script>
EOF

&footer("/", $text{'index'});
